/*
 * Erstellt mit SharpDevelop.
 * Benutzer: Jobe
 * Datum: 11.05.2007
 * Zeit: 19:29
 * 
 * Basis-LauncherPlus-Plugin
 * 1. Include PlugIn.cs
 * 2. Referenzen: System.Configuration, ..\PlugIn.csproj
 * 3. Projekt-Eigenschaften -> Kompilieren -> Ausgabepfad = ..\..\bin\plugins
 * 
 */
using System;
using System.Net;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using PlugIn;

namespace Roster
{

	public partial class Main : UserControl
	{
		public Main(IPlugin Plugin)
		{
			InitializeComponent();
		}
		
		public void DisplayProgress(byte[] Buffer, long Total, long Written){
			ASCIIEncoding encoding = new ASCIIEncoding( );
    		string BufferStr = encoding.GetString(Buffer);
			BufferStr = BufferStr.Replace("\t","  ");
			this.StatusStripProgressBar.Maximum = Convert.ToInt32( Total / 1024 );
			this.StatusStripProgressBar.Value = Convert.ToInt32( Written / 1024 );
			this.StatusStripLabel.Text = Written.ToString() + "/" + Total.ToString();
			this.ListBox.Items.Add(BufferStr);
		}
		
		public void RosterUpload(){
			// Upload to Roster
			/* http://launcherplus.googlecode.com/roster/update.php
			 * <form action="update.php" enctype="multipart/form-data" method="POST" onsubmit="submitonce(this)">
			 * <input type="file" accept="CharacterProfiler.lua" name="CharacterProfiler">
			 * <input type="file" accept="PvPLog.lua" name="PvPLog">
			 * <input type="password" name="password">
			 * */
			//string RosterAccount = PlugIn.Settings.LoadSetting( wow, "RosterAccount" );
			//string RosterURL = Settings.LoadSetting(wow,"RosterURL");
			/*block form closing events while uploading */
			/*try{
				if( ( RosterURL.Length > 0 )&&( RosterAccount.Length > 0 ) ){
					Roster r = new Roster(RosterURL);
					FileInfo fiCharacterProfiler = new FileInfo(InstallPath+"/WTF/Account/"+RosterAccount+"/SavedVariables/CharacterProfiler.lua");
					FileInfo fiPvPLog = new FileInfo(InstallPath+"/WTF/Account/"+RosterAccount+"/SavedVariables/PvPLog.lua");
					Hashtable CPsv = new Hashtable();
					if(fiCharacterProfiler.Exists)CPsv.Add("CharacterProfiler",fiCharacterProfiler.FullName);
					if(fiPvPLog.Exists)CPsv.Add("PvPLog",fiPvPLog.FullName);
					Roster.ProgressReport Report = new Roster.ProgressReport(DisplayProgress);
					ProgressBar.Value = ProgressBar.Minimum = 0;
					ProgressBar.Show();
					if(CPsv.Count>0)r.Upload(CPsv,Report);
					ProgressBar.Hide();
					StatusStripLabel.Text = "Done";
					RichTextBox.AppendText("\n\nDone.");
					RichTextBox.ScrollToCaret();
				}
			}catch(Exception ex){
				MessageBox.Show(this, "Failed to upload data:\n\n" + ex.Message, "Upload operation failed", MessageBoxButtons.OK, MessageBoxIcon.Stop);
			}/**/
		}
		
	}
}
